<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="../vue.js"></script>
  </head>
  <body>
    <div id="app">
      <ul>
        <li v-for="(tab, index) in tabs" @click="clickHandler(index)">
          {{tab.text}}
        </li>
      </ul>

      <ul>
        <!-- 先遍历再判断 -->
        <li v-for="(tab,index) in tabs" v-if="index === currentIndex ">
          {{tab.content}}
        </li>
      </ul>
    </div>
    <script>
      var tabs = [
        {
          text: "A",
          content: "A Content",
        },
        {
          text: "B",
          content: "B Content",
        },
        {
          text: "C",
          content: "C Content",
        },
      ];

      new Vue({
        el: "#app",
        data: {
          tabs: tabs,
          currentIndex: 0,
        },
        methods: {
          clickHandler: function (n) {
            // console.log(n);
            this.currentIndex = n;
          },
        },
      });
    </script>
  </body>
</html>
